home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / matrixc.zip / 3DEX2.C < prev    next >
C/C++ Source or Header  |  1990-05-10  |  2KB  |  118 lines

  1. /* Example of use of 3D routines to translate a cube on X and Y axes */
  2. /* Make using 
  3.    make make3dex.mak */
  4. /* Written by Nigel Salt */
  5.  
  6. #include <3d.h>
  7. #include <graph.h>
  8.  
  9. double dmatA[4][4];
  10. matrix matA={4,4,&dmatA[0][0]};
  11.  
  12. double dmatB[4][4];
  13. matrix matB={4,4,&dmatB[0][0]};
  14.  
  15. double dmatC[4][4];
  16. matrix matC={4,4,&dmatC[0][0]};
  17.  
  18. double dmatD[4][4];
  19. matrix matD={4,4,&dmatD[0][0]};
  20.  
  21. double dmatE[4][4];
  22. matrix matE={4,4,&dmatE[0][0]};
  23.  
  24. double dmatF[4][4];
  25. matrix matF={4,4,&dmatF[0][0]};
  26.  
  27. double dmatG[4][4];
  28. matrix matG={4,4,&dmatG[0][0]};
  29.  
  30. double dmatH[4][4];
  31. matrix matH={4,4,&dmatH[0][0]};
  32.  
  33. double dmatI[4][4];
  34. matrix matI={4,4,&dmatI[0][0]};
  35.  
  36. double dmatJ[4][4];
  37. matrix matJ={4,4,&dmatJ[0][0]};
  38.  
  39. double cubep[8][3]=
  40. {
  41.   1,1,1,
  42.   1,1,-1,
  43.   1,-1,-1,
  44.   1,-1,1,
  45.   -1,1,1,
  46.   -1,1,-1,
  47.   -1,-1,-1,
  48.   -1,-1,1
  49. };
  50. int cubel[12][2]=
  51. {
  52.   0,1,
  53.   1,2,
  54.   2,3,
  55.   3,0,
  56.   4,5,
  57.   5,6,
  58.   6,7,
  59.   7,4,
  60.   0,4,
  61.   1,5,
  62.   2,6,
  63.   3,7
  64. };
  65. object cube=
  66. {
  67.   8.0,12.0,&cubep[0][0],&cubel[0][0]
  68. };
  69.  
  70. double cubep2[8][3];
  71. int cubel2[12][2];
  72. object cube2=
  73. {
  74.   8.0,12.0,&cubep2[0][0],&cubel2[0][0]
  75. };
  76.  
  77. main()
  78. {
  79.   int i,j,axis;
  80.   double inc;
  81.   char buff[80];
  82.   init3d();
  83.   scale3(&matA,25,25,25);
  84.   objtran(&cube,&matA);
  85.   rot3(&matA,pi/8,2);
  86.   objtran(&cube,&matA);
  87.   rot3(&matA,pi/8,1);
  88.   objtran(&cube,&matA);
  89.  
  90.   for (j=0;j<4;j++)
  91.     {
  92.     axis=j%2;
  93.     inc=(j<2?1.0:-1.0);
  94.     tran3(&matA,(axis==0?inc:0),(axis==1?inc:0),0);
  95.     _settextposition(30,0);
  96.     sprintf(buff,"%c TRAN",'X'+axis);
  97.     _outtext(buff);
  98.     for (i=0;i<100;i++)
  99.       {
  100.       _setcolor(15);
  101.       objdraw(&cube);
  102.       objcop(&cube,&cube2);
  103.       objtran(&cube,&matA);
  104.       _setcolor(0);
  105.       objdraw(&cube2);
  106.       }
  107.     }
  108.   _setvideomode(_DEFAULTMODE);
  109. }
  110.  
  111. wait()
  112. {
  113.  _settextposition(30,0);
  114.  _outtext("PRESS KEY");
  115.  getch();
  116.  _clearscreen(_GCLEARSCREEN);
  117. }
  118.